package com.zonekey.entity.dto;

import com.zonekey.entity.dto.enums.ResultEnum;

/**
 * httpRequest请求返回的最外层对象
 * @author Creaated by gaoly
 * @date 2017/12/11 13:51
 **/
public class Result<T> {

    /**返回码**/
    private int code;

    /**错误信息**/
    private String msg;

    /**返回内容**/
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * @description:  返回Result实例
     * @param
     * @return com.zonekey.wisdomcloudplatform.utils.Result
     */
    public static Result instance(){
        return new Result();
    }


    /**
     * @description:  设置返回的resultMsg
     * @param resultMsgEnum
     * @return void
     */
    public void setResultEnum(ResultEnum resultMsgEnum){
        this.code = resultMsgEnum.getCode();
        this.msg = resultMsgEnum.getMsg();
    }

    //使用链式编程（方便编程）
    public static Result ok(){
        Result resultMsg = new Result();
        resultMsg.setResultEnum(ResultEnum.SUCCESS);
        return resultMsg;
    }

    public static Result fail(){
        Result resultMsg = new Result();
        resultMsg.setResultEnum(ResultEnum.FAILURE);
        return resultMsg;
    }


    public Result resultMsgEnum(ResultEnum resultMsgEnum){
        this.code = resultMsgEnum.getCode();
        this.msg = resultMsgEnum.getMsg();
        return this;
    }


    public Result msg(String msg){
        this.msg=msg;
        return this;
    }

    public Result data(T data){
        this.data=data;
        return this;
    }
}
